package com.hongyun.tms.common;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hongyun.tms.common.utils.MapperingUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 分页响应
 *
 * @author lipeng
 * @date 2024-05-31
 */
@Data
@NoArgsConstructor
public class PageResponseDto<T> {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "当前页码")
    private Long startPage;

    @ApiModelProperty(value = "当页数量")
    private Long pageSize;

    @ApiModelProperty(value = "总数量")
    private Long total;

    @ApiModelProperty(value = "数据列表")
    private List<T> records;

    @ApiModelProperty(value = "分页插件对象")
    private Page<T> page;

    public PageResponseDto(Page<T> page, final Class<T> voClass) {
        this.startPage = page.getCurrent();
        this.pageSize = (long)page.getRecords().size();
        this.total = page.getTotal();
        this.records = MapperingUtils.copyList(page.getRecords(), voClass);
    }

    public PageResponseDto(Page<T> page, List<T> lists) {
        this.startPage = page.getCurrent();
        this.pageSize = (long)page.getRecords().size();
        this.total = page.getTotal();
        this.records = lists;
    }

}
